package com.leyou.user.controller;

import com.leyou.user.entity.User;
import com.leyou.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author 黑马程序员
 * @Company http://www.itheima.com
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/check/{data}/{type}")
    public ResponseEntity<Boolean> checkUsernameAndPhone(@PathVariable("data") String data,
                                                         @PathVariable("type") Integer type) {
        return ResponseEntity.ok(userService.checkUsernameAndPhone(data, type));
    }

    @PostMapping("/code")
    public ResponseEntity<Void> sendCheckCode(@RequestParam("phone") String phone) {
        userService.sendCheckCode(phone);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }

    @PostMapping("/register")
    public ResponseEntity<Void> register(User user, @RequestParam("code") String code,@RequestParam("confirmPassword") String confirmPassword) {
        userService.register(user,code,confirmPassword);
        return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
    }
}
